/*
 * @Author: your name
 * @Date: 2021-02-27 23:28:16
 * @LastEditTime: 2021-07-22 16:34:33
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \vue3-antd-koa\koa-api\src\routers\article.js
 */
const article = require("../controllers/article")
const jwt = require('koa-jwt')
const config = require("../config")

/**
 * @type {Custom.IRouter}
 */
module.exports = router => {
	router.prefix("/api/articles")
	// router.use(
	// 	jwt({
	// 		secret: config.SECRET_KEY.TOKEN
	// 	}).unless({
	// 		method: ['GET']
	// 	})
	// )
	// 做路由TOKEN验证
	router.use(
		jwt({
			secret: config.SECRET_KEY.TOKEN
		}).unless({
			method: ['GET']
		})
	)

	router.get("/all/archives", article.archives)  // 放在前面，并且添加/all 方式与 /:id 产生冲突

	router.get("/", article.index)
	router.get("/:id", article.show)
	router.post("/", article.create)
	router.put("/:id", article.update)
	router.del("/:id", article.destroy)
}